'use strict';
const db=uniCloud.database()
exports.main = async (event, context) => {
	
	//console.log(""===null,null===0,"true"===true,"false"===false,null===undefined,""===0);
	
	//console.log(true==="",true==="true",true==="false",true==="0",true==="1",true===1,true===0);
	//event为客户端上传的参数
	const {
		question,
		answer,
		catagory
	}=event;
	if(question==null||question==""||question.trim()==""){
		return	{
			code:400,
			msg: 'question参数有误'
		};
	}
	if(answer==null||answer==""||answer.trim()==""){
		return	{
			code:400,
			msg: 'answer参数有误'
		};
	}
	// if(catogory==null||catogory==""||catogory.trim()==""){
	// 	return	{
	// 		code:400,
	// 		msg: 'catogory参数有误'
	// 	};
	// }
	await db.collection('questions').add({
		question:question.trim(),
		answer:answer.trim(),
		catagory:catagory,
		created:Date.now()
	})
	//返回数据给客户端
	return {
		code:200,
		msg: '数据添加成功'
	}
};
